﻿// -----------------------------------------------------------------------
// <copyright file="FormManager.cs" company="">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace NetFramework.Web
{
    using System;
    using System.Web;
    using System.Collections.Specialized;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class FormManager
    {
        public static NameValueCollection Collection
        {
            get
            {
                return HttpContext.Current.Request.Form;
            }
        }

        public static string Get(string key)
        {
            string value = Collection[key];
            if (value == null)
            {
                return string.Empty;
            }
            else
            {
                return value;
            }
        }

        public static T Get<T>(string key)
        {
            return Get<T>(key, default(T));
        }

        public static T Get<T>(string key, T defaultValue)
        {
            string value = Collection[key];
            if (string.IsNullOrEmpty(value))
            {
                return defaultValue;
            }

            return StringConvertTo.ConvertTo<T>(value);
        }
    }
}
